import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:base_library/base_library.dart';
import 'router/index.dart';
import 'package:provider/provider.dart';
import 'provider/theme_provider.dart';

class MyApp extends StatefulWidget {
  @override
  State createState() => _AppState();
}

class _AppState extends State<MyApp> {

  _AppState() {
    RouterHelper.setRouter(Router());// 初始化路由
    SpUtil.getInstance(); // 初始化 SpUtil
  }

  @override
  Widget build(BuildContext context) {

    return ChangeNotifierProvider<ThemeProvider> (
        create: (_) => ThemeProvider(),
        child: Consumer<ThemeProvider>(
            builder: (_, provider, __) {
              return MaterialApp(
                  title: '豆瓣电影',
                  // showPerformanceOverlay: true, //显示性能标签
                  // debugShowCheckedModeBanner: false, // 去除右上角debug的标签
                  // checkerboardRasterCacheImages: true,
                  // showSemanticsDebugger: true, // 显示语义视图
                  // checkerboardOffscreenLayers: true, // 检查离屏渲染
                  theme: getTheme(),
                  darkTheme: getTheme(isDarkMode: true),
                  themeMode: provider.getThemeMode(),
                  // home: SplashPage(),
                  onGenerateRoute: RouterHelper.router.generator,
                  // localizationsDelegates: const [ ],
                  // supportedLocales: const [ Locale('zh', 'CN'), Locale('en', 'US')],
              );
            }
        )
    );
  }

  /// 深色 浅色模式下的主题配色
  ThemeData getTheme({bool isDarkMode = false}) {
    return ThemeData(
        errorColor: isDarkMode ? Colors.red : Colors.red,
        brightness: isDarkMode ? Brightness.dark : Brightness.light,
        primaryColor: isDarkMode ? Colours.dark_primary : Colours.primary,
        accentColor: isDarkMode ? Colours.dark_accent : Colours.accent,
        backgroundColor: isDarkMode ? Colours.dark_app_bg : Colours.app_bg,
        // Tab指示器颜色
//        indicatorColor: isDarkMode ? Colors.dark_app_main : Colors.app_main,
        // 页面背景色
//        scaffoldBackgroundColor: isDarkMode ? Colors.dark_bg_color : Colors.white,
        // 主要用于Material背景色
//        canvasColor: isDarkMode ? Colors.dark_material_bg : Colors.white,
        // 文字选择色（输入框复制粘贴菜单）
//        textSelectionColor: Colors.app_main.withAlpha(70),
//        textSelectionHandleColor: Colors.app_main,
        textTheme: TextTheme(
          // TextField输入文字颜色
          subtitle1: isDarkMode ? TextStyles.textDark : TextStyles.text,
          // Text文字样式
          bodyText2: isDarkMode ? TextStyles.textDark : TextStyles.text,
          subtitle2: isDarkMode ? TextStyles.textDarkGray12 : TextStyles.textGray12,
        ),
        inputDecorationTheme: InputDecorationTheme(
          hintStyle: isDarkMode ? TextStyles.textHint14 : TextStyles.textDarkGray14,
        ),
        appBarTheme: AppBarTheme(
          elevation: 0.0,
          color: isDarkMode ? Colours.dark_bg_color : Colors.white,
          brightness: isDarkMode ? Brightness.dark : Brightness.light,
        ),
        dividerTheme: DividerThemeData(
            color: isDarkMode ? Colours.dark_line : Colours.line,
            space: 0.6,
            thickness: 0.6
        ),
//        cupertinoOverrideTheme: CupertinoThemeData(
//          brightness: isDarkMode ? Brightness.dark : Brightness.light,
//        )
    );
  }


}